package com.company.堆栈队列;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

/****
 * @author jianjian.zhang
 * @date 2022/07/17 20:11
 * @param
 * @return
 * @description: AB6表达式求值
 */


public class AB6表达式求值 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String str = input.nextLine();
        int res = new AB6表达式求值().solve(str);
        System.out.println(res);
    }
    public int solve(String s) {
        List<String> centerList = AnalyticExpression(s);
        List<String> postfixList = toPostfixExpression(centerList);
        int res = calculator(postfixList);
        return res;
    }

    private int calculator(List<String> postfixList) {
        Stack<String> stack = new Stack<>();
        for (String s : postfixList) {
            if (s.matches("\\d+")) {
                stack.push(s);
            } else {
                int num2 = Integer.parseInt(stack.pop());
                int num1 = Integer.parseInt(stack.pop());
                int result = 0;
                switch (s) {
                    case "+":
                        result = num1 + num2;
                        break;
                    case "-":
                        result = num1 - num2;
                        break;
                    case "*":
                        result = num1 * num2;
                        break;
                    case "/":
                        result = num1 / num2;
                        break;
                    default:
                        throw new RuntimeException("运算符不在 + - * / 内");
                }
                stack.push(String.valueOf(result));
            }
        }
        return Integer.parseInt(stack.peek());
    }

    private List<String> toPostfixExpression(List<String> centerList) {
        List<String> list = new ArrayList<>();
        Stack<String> s1 = new Stack<>();
        Stack<String> s2 = new Stack<>();
        for (int i = 0; i < centerList.size(); i++) {
            if (centerList.get(i).matches("\\d+")) {
                s2.push(centerList.get(i));
            } else if ("*".equals(centerList.get(i)) || "/".equals(centerList.get(i)) || "+".equals(centerList.get(i)) || "-".equals(centerList.get(i))) {
                if (s1.isEmpty() || s1.peek().equals("(")) {
                    s1.push(centerList.get(i));
                } else if (getLevel(centerList.get(i)) > getLevel(s1.peek())) {
                    s1.push(centerList.get(i));
                } else {
                    s2.push(s1.pop());
                    s1.push(centerList.get(i));
                }
            } else {
                if ("(".equals(centerList.get(i))) {
                    s1.push(centerList.get(i));
                } else if (")".equals(centerList.get(i))) {
                    while (!"(".equals(s1.peek())) {
                        s2.push(s1.pop());
                    }
                    s1.pop();  //  弹出左括号"("
                }
            }
        }
        while (!s1.isEmpty()) {
            s2.push(s1.pop());
        }
        while (!s2.isEmpty()) {
            s1.push(s2.pop());
        }
        while (!s1.isEmpty()) {
            list.add(s1.pop());
        }
        return list;
    }

    private static int getLevel(String str) {
        int level = 0;
        if ("*".equals(str) || "/".equals(str)) {
            level = 1;
        }
        return level;
    }

    private List<String> AnalyticExpression(String s) {
        List<String> list = new ArrayList<>();
        char c;
        String str = "";  //用于拼接多位数
        int i = 0;
        while (i < s.length()) {
            char c1 = s.charAt(i);
            if ((c = s.charAt(i)) < 48 || (c = s.charAt(i)) > 57) {
                list.add(c + "");
                i++;
            } else {
                str = "";
                while (i < s.length() && ((c = s.charAt(i)) >= 48 && (c = s.charAt(i)) <= 57)) {
                    str += c;
                    i++;
                }
                list.add(str);
            }
        }
        return list;
    }


}
